<?php
namespace app\index\controller;

use app\common\JwtToken;
use think\Controller;
use app\index\service\ReportService;
class Report extends Controller
{
    private $reportService;
    private $userId;

    /**
     * 依赖注入 Service
     *
     * @param ReportService $reportService
     * @author zws
     */
    public function __construct(ReportService $reportService)
    {
        parent::__construct();
        $this->reportService = $reportService;
        $token = $this->request->param('token');
        $this->userId = JwtToken::getTokenUid($token);
        $this->userId = 1;
    }

    /**
     * 查询项目
     * @return \think\response\Json
     * @author zws
     */
    public function index()
    {
        $input = $this->request->input;
        $input['user_id'] = $this->userId;
        $result = $this->reportService->index($input);
        return app_response(200, $result);
    }

    /**
     * 上传检测报告
     * @return \think\response\Json
     * @author zws
     */
    public function uploadReport()
    {
        $input = $this->request->input;
        $input['user_id'] = $this->userId;
        $input['report'] = request()->file('report');
        $result = $this->reportService->uploadReport($input);
        return app_response(200, $result);
    }

    /**
     * 获取报告地址
     * @return \think\response\Json
     * @author zws
     */
    public function downloadReport()
    {
        $input = $this->request->input;
        $input['user_id'] = $this->userId;
        $result = $this->reportService->downloadReport($input);
        return app_response(200, $result);
    }
}